const { render } = require( 'art-template' );
const express = require( 'express' );
const { join } = require( 'path' );

const app = express();
app.listen( 8080 );

// 指定art-template模板，并指定模块后缀为.html
app.engine( 'html', require( 'express-art-template' ) );
// 指定模板视图路径
app.set( 'views', join( __dirname, 'views' ) );
// 省略指定模块文件后缀后名称
app.set( 'view engine', 'html' );

app.get( '/', ( req, res ) => { 
    let username = '历史';
    let baidu = "<a href='http://www.baidu.com/'>百度一下</a>"
    let age = 26;
    let users = [
        { id:1, name:'张三' },
        { id:2, name:'里斯' },
        { id:3, name:'王五' },
    ]
    res.render('index', {
        username: username,
        baidu,
        age,
        users
    })
} );
app.get( '/a', ( req, res ) => {
    res.render( 'a' );
} );
app.get( '/b', ( req, res ) => {
    res.render( 'b' );
})